<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="utf-8">
  

  
  <title>JS高级题目</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta property="og:type" content="website">
<meta property="og:title" content="JS高级题目">
<meta property="og:url" content="https://github.com/NobleJohnnie/jsexam-github-io/index.html">
<meta property="og:site_name" content="JS高级题目">
<meta property="og:locale" content="default">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="JS高级题目">
  
    <link rel="alternate" href="/jsexam-github-io/atom.xml" title="JS高级题目" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/jsexam-github-io/css/style.css">
</head>
</html>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/jsexam-github-io/" id="logo">JS高级题目</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/jsexam-github-io/" id="subtitle">Js_Advance Tests</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/jsexam-github-io/">Home</a>
        
          <a class="main-nav-link" href="/jsexam-github-io/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/jsexam-github-io/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="https://github.com/NobleJohnnie/jsexam-github-io"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main">
  
    <article id="post-exam " class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/jsexam-github-io/2019/03/14/exam /" class="article-date">
  <time datetime="2019-03-14T07:09:32.896Z" itemprop="datePublished">2019-03-14</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="Exam"><a href="#Exam" class="headerlink" title="Exam"></a>Exam</h1><h2 id="2019-03-05"><a href="#2019-03-05" class="headerlink" title="2019-03-05"></a>2019-03-05</h2><h3 id="1-内存-数据-变量三者之间的关系"><a href="#1-内存-数据-变量三者之间的关系" class="headerlink" title="1. 内存,数据, 变量三者之间的关系"></a>1. 内存,数据, 变量三者之间的关系</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">内存是可以存储不同数据的容器</span><br><span class="line">变量与内存对应, 变量名是内存的标识名称, 变量值是内存中保存的数据</span><br></pre></td></tr></table></figure>
<h3 id="2-关于引用变量赋值的2个问题"><a href="#2-关于引用变量赋值的2个问题" class="headerlink" title="2. 关于引用变量赋值的2个问题"></a>2. 关于引用变量赋值的2个问题</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">2个引用变量指向同一个对象, 通过一个引用变量修改对象内部数据, 另一个引用变量也看得见</span><br><span class="line">2个引用变量指向同一个对象,让一个引用变量指向另一个对象, 另一个引用变量还是指向原来的对象</span><br></pre></td></tr></table></figure>
<h3 id="3-如何判断函数是否是回调函数"><a href="#3-如何判断函数是否是回调函数" class="headerlink" title="3. 如何判断函数是否是回调函数"></a>3. 如何判断函数是否是回调函数</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">你定义的</span><br><span class="line">你没有直接调用</span><br><span class="line">但它最终执行了</span><br></pre></td></tr></table></figure>
<h3 id="4-说说对象-数组-函数的区别"><a href="#4-说说对象-数组-函数的区别" class="headerlink" title="4. 说说对象,数组, 函数的区别"></a>4. 说说对象,数组, 函数的区别</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">对象: 一个可以存储多个无序数据的容器</span><br><span class="line">数组: 一个特别的对象, 存储的数据是有序的</span><br><span class="line">函数: 一个特别的对象, 包含可执行的代码(可以执行)</span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> p1 = &#123;<span class="attr">id</span>: <span class="number">1</span>, <span class="attr">name</span>: <span class="string">'Tom'</span>&#125;</span><br><span class="line"><span class="keyword">var</span> p2 = &#123;<span class="attr">id</span>: <span class="number">2</span>, <span class="attr">name</span>: <span class="string">'Tom2'</span>&#125;</span><br><span class="line"><span class="keyword">var</span> p3 = &#123;<span class="attr">id</span>: <span class="number">3</span>, <span class="attr">name</span>: <span class="string">'Tom'</span>&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> obj = &#123;&#125;</span><br><span class="line">obj[p1.id] = p1</span><br><span class="line">obj[p2.id] = p2</span><br><span class="line">obj[p3.id] = p3</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> arr = []</span><br><span class="line">arr.push(p1)</span><br><span class="line">arr.push(p2)</span><br><span class="line">arr.push(p3)</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> id = <span class="number">3</span></span><br><span class="line">arr.forEach (<span class="function"><span class="keyword">function</span> (<span class="params">p</span>)</span>&#123;<span class="keyword">if</span>(p.id===id)&#123;&#125;&#125;)</span><br><span class="line">obj[id]</span><br></pre></td></tr></table></figure>
<h3 id="5-如何判断函数中的this"><a href="#5-如何判断函数中的this" class="headerlink" title="5. 如何判断函数中的this"></a>5. 如何判断函数中的this</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">直接调用: xxx()  : window</span><br><span class="line">new调用: new xxx() : 新创建的对象</span><br><span class="line">对象调用: obj.xxx() : obj</span><br><span class="line">call/apply调用: xxx.call(obj) : obj</span><br></pre></td></tr></table></figure>
<h2 id="2019-03-06"><a href="#2019-03-06" class="headerlink" title="2019-03-06"></a>2019-03-06</h2><h3 id="6-git的6个基本操作"><a href="#6-git的6个基本操作" class="headerlink" title="6. git的6个基本操作"></a>6. git的6个基本操作</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">1). 创建本地仓库</span><br><span class="line">    创建.gitignore并配置忽略</span><br><span class="line">    git init</span><br><span class="line">    git add *</span><br><span class="line">    git commit -m &quot;xxx&quot;</span><br><span class="line">2). 创建远程仓库</span><br><span class="line">    New Repository</span><br><span class="line">    指定名称</span><br><span class="line">    创建</span><br><span class="line">3). 将本地仓库推送到远程仓库</span><br><span class="line">    git remote add origin https://github.com/zxfjd3g/xxx.git 关联远程仓库</span><br><span class="line">    git push origin master</span><br><span class="line">4). 如果本地有更新, 推送到远程</span><br><span class="line">    git add *</span><br><span class="line">    git commit -m &quot;xxx&quot;</span><br><span class="line">    git push origin master</span><br><span class="line">5). 如果远程有更新, 拉取到本地</span><br><span class="line">    git pull origin master</span><br><span class="line">6). 克隆远程仓库到本地</span><br><span class="line">    git clone https://github.com/zxfjd3g/xxx.git</span><br></pre></td></tr></table></figure>
<h3 id="7-说说原型与原型链"><a href="#7-说说原型与原型链" class="headerlink" title="7. 说说原型与原型链"></a>7. 说说原型与原型链</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">1). 所有函数都有prototype属性(显式原型), 属性值指向原型对象</span><br><span class="line">2). 所有实例对象都有__proto__属性(隐式原型), 其值就就等于构造函数的prototytpe属性值, 也就是也指向原型对象</span><br><span class="line">3). 多个对象通过__proto__属性就形成了链就是原型链, 在查找对象的某个属性时: 先在对象自身上找, 如果找不到就会沿着原型链查找</span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Foo</span> (<span class="params"></span>) </span>&#123;&#125;</span><br><span class="line"><span class="keyword">var</span> f1 = <span class="keyword">new</span> Foo()</span><br><span class="line"><span class="keyword">var</span> f2 = <span class="keyword">new</span> Foo()</span><br><span class="line"><span class="keyword">var</span> o1 = &#123;&#125;</span><br><span class="line"><span class="keyword">var</span> o2 = &#123;&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> obj1 = &#123;<span class="attr">m</span>: <span class="number">1</span>&#125;</span><br><span class="line"><span class="keyword">var</span> obj2 = &#123;<span class="attr">n</span>: <span class="number">2</span>&#125;</span><br><span class="line">obj1.xxx = obj2</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> parent = &#123;<span class="attr">name</span>: <span class="string">'tom'</span>&#125;</span><br><span class="line"><span class="keyword">var</span> child = &#123;<span class="attr">name</span>: <span class="string">'jack'</span>&#125;</span><br><span class="line">child.parent = parent</span><br><span class="line"><span class="keyword">var</span> child2 = &#123;<span class="attr">name</span>: <span class="string">'bob'</span>&#125;</span><br><span class="line">child2.parent = parent</span><br><span class="line">child2.parent.name</span><br><span class="line">parent.children = []</span><br><span class="line">parent.children.push(child)</span><br><span class="line">parent.children.push(child2)</span><br><span class="line"></span><br><span class="line">parent.children.forEach(<span class="function"><span class="keyword">function</span> (<span class="params">child</span>) </span>&#123;child.name&#125;)</span><br><span class="line"></span><br><span class="line">a.b</span><br></pre></td></tr></table></figure>
<h3 id="8-说说变量提升和函数提升"><a href="#8-说说变量提升和函数提升" class="headerlink" title="8. 说说变量提升和函数提升"></a>8. 说说变量提升和函数提升</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">1). 变量提升: 在用var声明变量的语句之前就可以访问到变量 ==&gt; var声明变量部分被提前执行了</span><br><span class="line">2). 函数提升: 在function函数声明语句之前就可以调用函数 ==&gt; 函数声明语句被提前执行了</span><br><span class="line">3). 原因: JS引擎在执行代码时做了预处理/解析的工作</span><br></pre></td></tr></table></figure>
<h3 id="9-说说作用域与作用域链"><a href="#9-说说作用域与作用域链" class="headerlink" title="9. 说说作用域与作用域链"></a>9. 说说作用域与作用域链</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">1). 作用域: 变量可见的一块特定代码区域, 包括全局作用域和函数作用域, 作用域在编写代码时就确定了</span><br><span class="line">2). 作用域链: 由内向外的多个嵌套作用域形成的链, 在查找变量时, 会沿着作用域链查找</span><br></pre></td></tr></table></figure>
<h3 id="10-画内存详图"><a href="#10-画内存详图" class="headerlink" title="10. 画内存详图"></a>10. 画内存详图</h3><p><img src="https://s2.ax1x.com/2019/03/14/AA3sqs.png" alt="原型链图"></p>
<h2 id="2019-03-07"><a href="#2019-03-07" class="headerlink" title="2019-03-07"></a>2019-03-07</h2><h3 id="11-产生闭包的条件与什么是闭包"><a href="#11-产生闭包的条件与什么是闭包" class="headerlink" title="11. 产生闭包的条件与什么是闭包"></a>11. 产生闭包的条件与什么是闭包</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">1). 产生闭包的条件</span><br><span class="line">    * 函数嵌套</span><br><span class="line">    * 内部函数引用了外部函数的数据(变量/函数)</span><br><span class="line">    * 执行外部函数</span><br><span class="line">2). 什么是闭包</span><br><span class="line">    闭包本质是内部函数中的一个容器, 这个容器中包含引用的变量</span><br></pre></td></tr></table></figure>
<h3 id="12-编写程序演示闭包"><a href="#12-编写程序演示闭包" class="headerlink" title="12. 编写程序演示闭包"></a>12. 编写程序演示闭包</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">fn1</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="keyword">var</span> a = <span class="number">3</span></span><br><span class="line">  <span class="function"><span class="keyword">function</span> <span class="title">fn2</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    a++</span><br><span class="line">    <span class="built_in">console</span>.log(a)</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> fn2</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> f = fn1()</span><br><span class="line">f() <span class="comment">// 4</span></span><br><span class="line">f() <span class="comment">// 5</span></span><br></pre></td></tr></table></figure>
<h3 id="13-对象创建模式-4种"><a href="#13-对象创建模式-4种" class="headerlink" title="13. 对象创建模式(4种)"></a>13. 对象创建模式(4种)</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//1). Object构造函数模式</span></span><br><span class="line">  <span class="keyword">var</span> obj = &#123;&#125;</span><br><span class="line">  obj.name = <span class="string">'Tom'</span></span><br><span class="line">  obj.setName = <span class="function"><span class="keyword">function</span>(<span class="params">name</span>)</span>&#123;<span class="keyword">this</span>.name=name&#125;</span><br><span class="line"><span class="comment">//2). 对象字面量模式</span></span><br><span class="line">  <span class="keyword">var</span> obj = &#123;</span><br><span class="line">    name : <span class="string">'Tom'</span>,</span><br><span class="line">    setName : <span class="function"><span class="keyword">function</span>(<span class="params">name</span>)</span>&#123;<span class="keyword">this</span>.name = name&#125;</span><br><span class="line">  &#125;</span><br><span class="line"><span class="comment">//3). 构造函数模式</span></span><br><span class="line">  <span class="function"><span class="keyword">function</span> <span class="title">Person</span>(<span class="params">name, age</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">this</span>.name = name</span><br><span class="line">    <span class="keyword">this</span>.age = age</span><br><span class="line">    <span class="keyword">this</span>.setName = <span class="function"><span class="keyword">function</span>(<span class="params">name</span>)</span>&#123;<span class="keyword">this</span>.name=name&#125;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">new</span> Person(<span class="string">'tom'</span>, <span class="number">12</span>)</span><br><span class="line"><span class="comment">//4). 构造函数+原型的组合模式</span></span><br><span class="line">  <span class="function"><span class="keyword">function</span> <span class="title">Person</span>(<span class="params">name, age</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">this</span>.name = name</span><br><span class="line">    <span class="keyword">this</span>.age = age</span><br><span class="line">  &#125;</span><br><span class="line">  Person.prototype.setName = <span class="function"><span class="keyword">function</span>(<span class="params">name</span>)</span>&#123;<span class="keyword">this</span>.name=name&#125;</span><br><span class="line">  <span class="keyword">new</span> Person(<span class="string">'tom'</span>, <span class="number">12</span>)</span><br></pre></td></tr></table></figure>
<h3 id="14-编码实现组合继承模式"><a href="#14-编码实现组合继承模式" class="headerlink" title="14. 编码实现组合继承模式"></a>14. 编码实现组合继承模式</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Parent</span>(<span class="params">xxx</span>)</span>&#123;<span class="keyword">this</span>.xxx = xxx&#125;</span><br><span class="line">Parent.prototype.test = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;&#125;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Child</span>(<span class="params">xxx,yyy</span>)</span>&#123;</span><br><span class="line">  Parent.call(<span class="keyword">this</span>, xxx) <span class="comment">//借用构造函数   this.Parent(xxx)</span></span><br><span class="line">&#125;</span><br><span class="line">Child.prototype = <span class="keyword">new</span> Parent() <span class="comment">//得到test()</span></span><br><span class="line">Child.proptotype.constructor = Child</span><br><span class="line">Child.prototype.test2 = <span class="function"><span class="keyword">function</span> (<span class="params"></span>)</span>&#123;&#125;</span><br><span class="line"><span class="keyword">var</span> child = <span class="keyword">new</span> Child() <span class="comment">//child.xxx为'a', 也有test()</span></span><br></pre></td></tr></table></figure>
<h3 id="15-下面代码的输出"><a href="#15-下面代码的输出" class="headerlink" title="15. 下面代码的输出"></a>15. 下面代码的输出</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; <span class="number">3</span>; i++) &#123;</span><br><span class="line">    setTimeout(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(i);</span><br><span class="line">    &#125;, <span class="number">0</span>);</span><br><span class="line">    <span class="built_in">console</span>.log(i);</span><br><span class="line">&#125; <span class="comment">// 0 1 2 3 3 3</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; <span class="number">5</span>; i++) &#123; </span><br><span class="line">    (<span class="function"><span class="keyword">function</span>(<span class="params">i</span>)</span>&#123;</span><br><span class="line">        setTimeout(<span class="function"><span class="keyword">function</span> (<span class="params"></span>)</span>&#123;</span><br><span class="line">            <span class="built_in">console</span>.log(i);  </span><br><span class="line">         &#125;,<span class="number">1000</span>);  </span><br><span class="line">    &#125;)(i);  </span><br><span class="line">&#125; <span class="comment">// 0 1 2 3 4</span></span><br></pre></td></tr></table></figure>
<h2 id="2019-03-08"><a href="#2019-03-08" class="headerlink" title="2019-03-08"></a>2019-03-08</h2><h3 id="16-简述一下js有几种数据类型？"><a href="#16-简述一下js有几种数据类型？" class="headerlink" title="16.简述一下js有几种数据类型？"></a>16.简述一下js有几种数据类型？</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">//1.基础数据类型：（简记：nubnss）</span><br><span class="line">null，undefined，boolean，number，string，symbol</span><br><span class="line"></span><br><span class="line">//2.对象(引用，复合)类型</span><br><span class="line">Object，Array，Function</span><br></pre></td></tr></table></figure>
<h3 id="17-typeof的返回值有几种？typeof有什么特点？"><a href="#17-typeof的返回值有几种？typeof有什么特点？" class="headerlink" title="17.typeof的返回值有几种？typeof有什么特点？"></a>17.typeof的返回值有几种？typeof有什么特点？</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&gt;Typeof：一个不正确，两个不精确，其余都准确。</span><br><span class="line">&gt;一个不正确：typeof(null)的结果是object。</span><br><span class="line">&gt;两个不精确：typeof []和&#123;&#125; 的结果都是object</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">typeof 1 // &apos;number&apos;</span><br><span class="line">typeof &apos;1&apos; // &apos;string&apos;</span><br><span class="line">typeof undefined // &apos;undefined&apos;</span><br><span class="line">typeof true // &apos;boolean&apos;</span><br><span class="line">typeof console.log // &apos;function&apos;</span><br><span class="line">typeof Symbol() // &apos;symbol&apos;</span><br><span class="line">typeof b // b 没有声明，但是还会显示 undefined</span><br><span class="line">typeof [] // &apos;object&apos;</span><br><span class="line">typeof &#123;&#125; // &apos;object&apos;</span><br><span class="line">typeof null // &apos;object&apos;</span><br></pre></td></tr></table></figure>
<h3 id="18-说一下null与undefined？"><a href="#18-说一下null与undefined？" class="headerlink" title="18.说一下null与undefined？"></a>18.说一下null与undefined？</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&gt;undefined：没有赋值（一般不会将一个变量手动赋值为undefined，因为没有意义）</span><br><span class="line">	var a;</span><br><span class="line">	console.log(a)//undefined</span><br><span class="line">	console.log(b)//undefined</span><br><span class="line">	var b = 1;</span><br><span class="line"></span><br><span class="line">&gt;null：赋值了, 但是值为null	</span><br><span class="line">	//一个约定俗称的小规矩，一般赋值为null代表这个变量接下来要存储的类型是对象</span><br><span class="line">	var a = null</span><br></pre></td></tr></table></figure>
<h3 id="19-说出下列语句的结果"><a href="#19-说出下列语句的结果" class="headerlink" title="19.说出下列语句的结果"></a>19.说出下列语句的结果</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">console.log(1 + &apos;1&apos;)//&apos;11&apos;</span><br><span class="line">console.log(&apos;1&apos;- 0)//1</span><br><span class="line">console.log(2 * &apos;2&apos;)//4</span><br><span class="line">console.log([1, 2] + [2, 1])//1,22,1</span><br><span class="line">console.log(typeof console.log(&apos;1&apos;- 0))// 1 undefined</span><br></pre></td></tr></table></figure>
<h3 id="20-控制台输出什么？"><a href="#20-控制台输出什么？" class="headerlink" title="20.控制台输出什么？"></a>20.控制台输出什么？</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">var obj = &#123;</span><br><span class="line">  fn2: function () &#123;</span><br><span class="line">     console.log(fn2)</span><br><span class="line">    // 如果想输出fn2属性的值，这么写：console.log(this.fn2) 或者 obj.fn2才行。</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line">obj.fn2() //报错， fn2 is not defined</span><br></pre></td></tr></table></figure>
<h2 id="2019-03-09"><a href="#2019-03-09" class="headerlink" title="2019-03-09"></a>2019-03-09</h2><h3 id="21-写出以下代码段的执行结果"><a href="#21-写出以下代码段的执行结果" class="headerlink" title="21.写出以下代码段的执行结果"></a>21.写出以下代码段的执行结果</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">var a = 2</span><br><span class="line">function fn() &#123;</span><br><span class="line">  console.log(a)</span><br><span class="line">  var a = 3</span><br><span class="line">&#125;</span><br><span class="line">fn() // undefined</span><br></pre></td></tr></table></figure>
<h3 id="22-写出以下代码段的执行结果"><a href="#22-写出以下代码段的执行结果" class="headerlink" title="22.写出以下代码段的执行结果"></a>22.写出以下代码段的执行结果</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> c</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">c</span>(<span class="params">c</span>) </span>&#123;</span><br><span class="line"> <span class="built_in">console</span>.log(c)</span><br><span class="line"> <span class="keyword">var</span> c = <span class="number">3</span></span><br><span class="line">&#125;</span><br><span class="line">c = <span class="number">1</span></span><br><span class="line"><span class="built_in">console</span>.log(c) <span class="comment">// 1</span></span><br><span class="line">c(<span class="number">2</span>) <span class="comment">//报错  c is not a function</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">* 解析：</span></span><br><span class="line"><span class="comment">* 1.预处理的结果：c是function。</span></span><br><span class="line"><span class="comment">* 2.正常执行代码，跳过function c（因为已经与解析完），后来c变成了1</span></span><br><span class="line"><span class="comment">* 3.打印c是1，执行1，1明显不是函数，报错</span></span><br><span class="line"><span class="comment">*</span></span><br><span class="line"><span class="comment">* */</span></span><br></pre></td></tr></table></figure>
<h3 id="23-写出以下代码段的执行结果"><a href="#23-写出以下代码段的执行结果" class="headerlink" title="23.写出以下代码段的执行结果"></a>23.写出以下代码段的执行结果</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> c</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">c</span>(<span class="params">c</span>) </span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(c)</span><br><span class="line">  c = <span class="number">3</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(c) <span class="comment">// 函数体</span></span><br><span class="line">c(<span class="number">2</span>) <span class="comment">//2</span></span><br></pre></td></tr></table></figure>
<h3 id="24-写出控制台输出结果"><a href="#24-写出控制台输出结果" class="headerlink" title="24.写出控制台输出结果"></a>24.写出控制台输出结果</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = &#123;</span><br><span class="line">  fn2: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">     <span class="built_in">console</span>.log(fn2)</span><br><span class="line">    <span class="comment">// 如果想输出fn2属性的值，这么写：console.log(this.fn2) 或者 obj.fn2也行, 但比较死。</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line">obj.fn2() <span class="comment">//报错， fn2 is not defined</span></span><br></pre></td></tr></table></figure>
<h3 id="25-写出控制台输出结果"><a href="#25-写出控制台输出结果" class="headerlink" title="25.写出控制台输出结果"></a>25.写出控制台输出结果</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">function fn() &#123;</span><br><span class="line">  console.log(a)</span><br><span class="line">  var a = 3</span><br><span class="line">&#125;</span><br><span class="line">fn() // undefined</span><br><span class="line">//解析：函数内部预处理，不去找全局的a，同时变量提升，打印之前a定义了，还未赋值，undefined</span><br></pre></td></tr></table></figure>
<h2 id="2019-03-11"><a href="#2019-03-11" class="headerlink" title="2019-03-11"></a>2019-03-11</h2><h3 id="26-写出控制台输出结果"><a href="#26-写出控制台输出结果" class="headerlink" title="26.写出控制台输出结果"></a>26.写出控制台输出结果</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">fn2</span>(<span class="params"></span>) </span>&#123; <span class="comment">// 预计处理:</span></span><br><span class="line">  <span class="built_in">console</span>.log(a)</span><br><span class="line">  a = <span class="number">3</span>  <span class="comment">// 此时的a是全局变量</span></span><br><span class="line">&#125;</span><br><span class="line">fn2() <span class="comment">// a is not defined</span></span><br></pre></td></tr></table></figure>
<h3 id="27-你所知道的常见拷贝技术？都分别都有什么问题或特点？"><a href="#27-你所知道的常见拷贝技术？都分别都有什么问题或特点？" class="headerlink" title="27.你所知道的常见拷贝技术？都分别都有什么问题或特点？"></a>27.你所知道的常见拷贝技术？都分别都有什么问题或特点？</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">1. arr.concat(): 数组浅拷贝</span><br><span class="line">2. arr.slice(): 数组浅拷贝</span><br><span class="line">3. JSON.parse(JSON.stringify(arr/obj)): 数组或对象深拷贝, 但不能处理函数数据</span><br></pre></td></tr></table></figure>
<h3 id="28-请编写一个函数，完成深度复制对象类型的数据"><a href="#28-请编写一个函数，完成深度复制对象类型的数据" class="headerlink" title="28.请编写一个函数，完成深度复制对象类型的数据"></a>28.请编写一个函数，完成深度复制对象类型的数据</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//判断数据类型的方法</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getTYpe</span>(<span class="params">target</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="built_in">Object</span>.prototype.toString.call(target).slice(<span class="number">8</span>,<span class="number">-1</span>)</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">clone</span>(<span class="params">target</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">let</span> result</span><br><span class="line">  <span class="keyword">if</span>(getTYpe(target) === <span class="string">'Object'</span>)&#123;</span><br><span class="line">    result = &#123;&#125;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">else</span> <span class="keyword">if</span>(getTYpe(target) === <span class="string">'Array'</span>)&#123;</span><br><span class="line">    result = []</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">else</span>&#123;</span><br><span class="line">    <span class="keyword">return</span> target</span><br><span class="line">  &#125;</span><br><span class="line">  </span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">let</span> key <span class="keyword">in</span> target)&#123;</span><br><span class="line">     <span class="keyword">let</span> item = target[key]</span><br><span class="line">      <span class="keyword">if</span>(getTYpe(item) === <span class="string">'Object'</span>||<span class="string">'Array'</span>)&#123;</span><br><span class="line">        result[key] = clone(item)</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="keyword">else</span>&#123;</span><br><span class="line">        result[key] = item</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  <span class="keyword">return</span> result</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>
<h3 id="29-写出控制台输出结果"><a href="#29-写出控制台输出结果" class="headerlink" title="29.写出控制台输出结果"></a>29.写出控制台输出结果</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> name = <span class="string">'World!'</span>;</span><br><span class="line">(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="keyword">if</span> (<span class="keyword">typeof</span> name === <span class="string">'undefined'</span>) &#123;</span><br><span class="line">    <span class="keyword">var</span> name = <span class="string">'Jack'</span></span><br><span class="line">    <span class="built_in">console</span>.log(name)</span><br><span class="line">  &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    <span class="built_in">console</span>.log(name)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;)()</span><br><span class="line"><span class="comment">//最终输出：Jack</span></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">* 解析：</span></span><br><span class="line"><span class="comment">* 1.预处理结果，外部name是undefined，内部name是undefined。</span></span><br><span class="line"><span class="comment">*   这里值得注意的是：不管if判断是否为真，内部的name都会在预解析的时候变为undefined，ES6之前不存在块级作用域。</span></span><br><span class="line"><span class="comment">* 2.执行代码：外部name是World，内部是undefined。</span></span><br><span class="line"><span class="comment">* 3.进入if判断，内部name为Jack。</span></span><br><span class="line"><span class="comment">* */</span></span><br></pre></td></tr></table></figure>
<h3 id="30-写出控制台输出结果"><a href="#30-写出控制台输出结果" class="headerlink" title="30.写出控制台输出结果"></a>30.写出控制台输出结果</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = <span class="number">6</span></span><br><span class="line">setTimeout(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="number">0</span>)</span><br><span class="line">  <span class="built_in">console</span>.log(a)</span><br><span class="line">  a = <span class="number">666</span></span><br><span class="line">&#125;, <span class="number">0</span>)</span><br><span class="line"><span class="built_in">console</span>.log(<span class="number">1</span>)</span><br><span class="line">a = <span class="number">66</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">* 解析：</span></span><br><span class="line"><span class="comment">* 1.虽然setTimeout的时间是0，但是浏览器的循环，所有的事件管理模块，都会在等当前主线程代码运行完毕后</span></span><br><span class="line"><span class="comment">*   事件管理模块才根据自己的触发条件，将自己管理的事件放在执行队列里，所以是0，也要等着！等着console.log(1)</span></span><br><span class="line"><span class="comment">*   和a = 66全部执行完。</span></span><br><span class="line"><span class="comment">* 2.最终结果是：控制台打印：1，0，66。</span></span><br><span class="line"><span class="comment">* */</span></span><br></pre></td></tr></table></figure>
<h2 id="2019-03-12"><a href="#2019-03-12" class="headerlink" title="2019-03-12"></a>2019-03-12</h2><h3 id="31-写出控制台输出结果"><a href="#31-写出控制台输出结果" class="headerlink" title="31.写出控制台输出结果"></a>31.写出控制台输出结果</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = &#123; </span><br><span class="line">    fn2: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123; </span><br><span class="line">        <span class="built_in">console</span>.log(fn2) </span><br><span class="line">    &#125; </span><br><span class="line">  &#125; </span><br><span class="line">obj.fn2()</span><br></pre></td></tr></table></figure>
<h3 id="32-写出控制台输出结果"><a href="#32-写出控制台输出结果" class="headerlink" title="32.写出控制台输出结果"></a>32.写出控制台输出结果</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">fn</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(a)</span><br><span class="line">    <span class="keyword">var</span> a = <span class="number">3</span></span><br><span class="line">  &#125;</span><br><span class="line">fn()</span><br></pre></td></tr></table></figure>
<h3 id="33-写出控制台输出结果"><a href="#33-写出控制台输出结果" class="headerlink" title="33.写出控制台输出结果"></a>33.写出控制台输出结果</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">fn2</span>(<span class="params"></span>) </span>&#123; </span><br><span class="line">    <span class="built_in">console</span>.log(a)</span><br><span class="line">    a = <span class="number">3</span> </span><br><span class="line">&#125;</span><br><span class="line">fn2()</span><br></pre></td></tr></table></figure>
<h3 id="34-你所知道的常见拷贝技术？都分别都有什么问题或特点？"><a href="#34-你所知道的常见拷贝技术？都分别都有什么问题或特点？" class="headerlink" title="34.你所知道的常见拷贝技术？都分别都有什么问题或特点？"></a>34.你所知道的常见拷贝技术？都分别都有什么问题或特点？</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">常用的拷贝技术</span><br><span class="line">1). arr.concat(): 数组浅拷贝</span><br><span class="line">2). arr.slice(): 数组浅拷贝</span><br><span class="line">3). JSON.parse(JSON.stringify(arr/obj)): 数组或对象深拷贝, 但不能处理函数数据</span><br><span class="line">4). 浅拷贝包含函数数据的对象/数组</span><br><span class="line">5). 深拷贝包含函数数据的对象/数组</span><br></pre></td></tr></table></figure>
<h3 id="35-请编写一个函数，完成深度复制对象类型的数据"><a href="#35-请编写一个函数，完成深度复制对象类型的数据" class="headerlink" title="35.请编写一个函数，完成深度复制对象类型的数据"></a>35.请编写一个函数，完成深度复制对象类型的数据</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//判断数据类型的方法</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getTYpe</span>(<span class="params">target</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="built_in">Object</span>.prototype.toString.call(target).slice(<span class="number">8</span>,<span class="number">-1</span>)</span><br><span class="line">&#125;</span><br><span class="line">g</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 深度复制的方法</span></span><br><span class="line"><span class="comment"> * @param target</span></span><br><span class="line"><span class="comment"> * @returns &#123;*&#125;</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">clone</span>(<span class="params">target</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">let</span> result</span><br><span class="line">  <span class="keyword">if</span>(getTYpe(target) === <span class="string">'Object'</span>)&#123;</span><br><span class="line">    result = &#123;&#125;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">else</span> <span class="keyword">if</span>(getTYpe(target) === <span class="string">'Array'</span>)&#123;</span><br><span class="line">    result = []</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">else</span>&#123;</span><br><span class="line">    <span class="keyword">return</span> target</span><br><span class="line">  &#125;</span><br><span class="line">  </span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">let</span> key <span class="keyword">in</span> target)&#123;</span><br><span class="line">     <span class="keyword">let</span> item = target[key]</span><br><span class="line">      <span class="keyword">if</span>(getTYpe(item) === <span class="string">'Object'</span>||<span class="string">'Array'</span>)&#123;</span><br><span class="line">        result[key] = clone(item)</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="keyword">else</span>&#123;</span><br><span class="line">        result[key] = item</span><br><span class="line">      &#125;</span><br><span class="line">  &#125;</span><br><span class="line"><span class="keyword">return</span> result</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="2019-03-13"><a href="#2019-03-13" class="headerlink" title="2019-03-13"></a>2019-03-13</h2><h3 id="36-说说你所知道的js模块化技术"><a href="#36-说说你所知道的js模块化技术" class="headerlink" title="36.说说你所知道的js模块化技术"></a>36.说说你所知道的js模块化技术</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">1. CommonJS（后端常用）</span><br><span class="line">	2. AMD</span><br><span class="line">	3. CMD</span><br><span class="line">	4. ES6（前端常用）</span><br></pre></td></tr></table></figure>
<h3 id="37-说出以下代码执行结果"><a href="#37-说出以下代码执行结果" class="headerlink" title="37.说出以下代码执行结果"></a>37.说出以下代码执行结果</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">fn1</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="keyword">var</span> a = <span class="number">2</span></span><br><span class="line">  <span class="function"><span class="keyword">function</span> <span class="title">fn2</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    a++</span><br><span class="line">    <span class="built_in">console</span>.log(a)</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> fn2</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> f = fn1()</span><br><span class="line">f()</span><br><span class="line">f()</span><br><span class="line"><span class="comment">// 3</span></span><br><span class="line"><span class="comment">// 4</span></span><br></pre></td></tr></table></figure>
<h3 id="38-说出以下代码执行结果"><a href="#38-说出以下代码执行结果" class="headerlink" title="38.说出以下代码执行结果"></a>38.说出以下代码执行结果</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> name = <span class="string">"A"</span></span><br><span class="line"><span class="keyword">var</span> object = &#123;</span><br><span class="line">  name: <span class="string">"B"</span>,</span><br><span class="line">  getNameFunc: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">      <span class="keyword">return</span> <span class="keyword">this</span>.name </span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(object.getNameFunc()())  <span class="comment">//A</span></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">* 1. object.getNameFunc()的this是object，返回了1个function</span></span><br><span class="line"><span class="comment">* 2. 再次调用返回的object时，此时是函数直接调用，this是window</span></span><br><span class="line"><span class="comment">* */</span></span><br></pre></td></tr></table></figure>
<h3 id="39-请说说node-js有哪些特点？"><a href="#39-请说说node-js有哪些特点？" class="headerlink" title="39.请说说node.js有哪些特点？"></a>39.请说说node.js有哪些特点？</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">1) 异步非阻塞的I/O（I/O线程池）</span><br><span class="line">2) 特别适用于I/O密集型应用</span><br><span class="line">3) 单线程</span><br><span class="line">4) 处理不好CPU密集型服务</span><br></pre></td></tr></table></figure>
<h3 id="40-说说你对Node中的Buffer缓冲器的了解"><a href="#40-说说你对Node中的Buffer缓冲器的了解" class="headerlink" title="40.说说你对Node中的Buffer缓冲器的了解"></a>40.说说你对Node中的Buffer缓冲器的了解</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">1.它是一个类数组的对象，用于存储数据（存储的全部是二进制数据）</span><br><span class="line">2.Buffer的效率很高，存储和读取的速度都很快，本质就是对内存的直接操作</span><br><span class="line">3.Buffer的大小一旦确定了，不可修改。</span><br><span class="line">4.每个元素占用内存的空间是1字节。</span><br><span class="line">5.Buffer是Node中非常核心的模块，无需下载，无需引入，直接可以使用</span><br></pre></td></tr></table></figure>
<h2 id="2019-03-16"><a href="#2019-03-16" class="headerlink" title="2019-03-16"></a>2019-03-16</h2><h3 id="41-说出程序执行结果"><a href="#41-说出程序执行结果" class="headerlink" title="41.说出程序执行结果"></a>41.说出程序执行结果</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Person</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  getAge = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="number">10</span>)</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> <span class="keyword">this</span></span><br><span class="line">&#125;</span><br><span class="line">Person.getAge = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="number">20</span>)</span><br><span class="line">&#125;</span><br><span class="line">Person.prototype.getAge = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="number">30</span>)</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> getAge = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="number">40</span>)</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getAge</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="number">50</span>)</span><br><span class="line">&#125;</span><br><span class="line">Person.getAge() </span><br><span class="line">getAge()</span><br><span class="line">Person().getAge() </span><br><span class="line">getAge()</span><br><span class="line"><span class="keyword">new</span> Person.getAge() </span><br><span class="line"><span class="keyword">new</span> Person().getAge() </span><br><span class="line"><span class="comment">/*  Person.getAge() //20 把Person看成对象，调用对象里的一个方法，执行Person.getAge = function ()...</span></span><br><span class="line"><span class="comment">    getAge() //40 执行全局的getAge，全局有两个，不过用var声明的那个是有效的.</span></span><br><span class="line"><span class="comment">    Person().getAge() //10 先执行Person()，执行的结果是:全局的getAge被重写，返回的this是window，执行35行（此时已被覆盖）</span></span><br><span class="line"><span class="comment">    getAge() //10 执行全局的那个，已经被覆盖了，是10</span></span><br><span class="line"><span class="comment">    new Person.getAge() //20 Person是对象，执行对象.方法，输出20</span></span><br><span class="line"><span class="comment">    new Person().getAge() //30 new Person()是Person的一个实例，实例调用getAge，自己没有找原型，找到了，30.*/</span></span><br></pre></td></tr></table></figure>
<h3 id="42-请说出搭建原生Node服务的几个关键步骤"><a href="#42-请说出搭建原生Node服务的几个关键步骤" class="headerlink" title="42.请说出搭建原生Node服务的几个关键步骤"></a>42.请说出搭建原生Node服务的几个关键步骤</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//1.引入http模块</span></span><br><span class="line"><span class="keyword">let</span> http = <span class="built_in">require</span>(<span class="string">'http'</span>)</span><br><span class="line"><span class="comment">//2.创建一个服务对象</span></span><br><span class="line"><span class="keyword">let</span> server = http.createServer(<span class="function">(<span class="params">request,response</span>)=&gt;</span>&#123;</span><br><span class="line">  <span class="comment">//返回响应</span></span><br><span class="line">  response.end(<span class="string">'&lt;h3&gt;这是我的第一个原生node服务器&lt;/h3&gt;'</span>)</span><br><span class="line">&#125;)</span><br><span class="line"><span class="comment">//3.绑定端口号</span></span><br><span class="line">server.listen(<span class="number">3000</span>,(err)=&gt;&#123;</span><br><span class="line">  <span class="keyword">if</span> (!err) <span class="built_in">console</span>.log(<span class="string">'服务器启动成功了,访问地址是：http://localhost:3000'</span>)</span><br><span class="line">  <span class="keyword">else</span> <span class="built_in">console</span>.log(<span class="string">'服务器启动失败，'</span>+err)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<h3 id="43-简要说一下你对MongoDB的了解"><a href="#43-简要说一下你对MongoDB的了解" class="headerlink" title="43.简要说一下你对MongoDB的了解"></a>43.简要说一下你对MongoDB的了解</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">1.它是最具代表性的非关系行数据库（NoSQL）。</span><br><span class="line">2.MongoDB是文档结构的存储方式，类JSON数据模式，能够更便捷的获取数据。</span><br><span class="line">3.它不像关系型统数据库有严格的字段约束，更加灵活多变。</span><br><span class="line">4.不支持事务（事务不可分割，具有原子性），一般关系型数据库都支持事务。</span><br></pre></td></tr></table></figure>
<p>44</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="https://github.com/NobleJohnnie/jsexam-github-io/2019/03/14/exam /" data-id="cjtb3br06000090uu4510e5zx" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  


</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/jsexam-github-io/archives/2019/03/">March 2019</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/jsexam-github-io/2019/03/14/exam /">(no title)</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2019 Antonio<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/jsexam-github-io/" class="mobile-nav-link">Home</a>
  
    <a href="/jsexam-github-io/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/jsexam-github-io/fancybox/jquery.fancybox.css">
  <script src="/jsexam-github-io/fancybox/jquery.fancybox.pack.js"></script>


<script src="/jsexam-github-io/js/script.js"></script>



  </div>
</body>
</html>